package com.voxel.sense.infomsg;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.com.common.utils.AppUtils;
import com.voxel.sense.infomsg.utils.GlideUtils;
import com.voxel.sense.infomsg.utils.ResourceUtil;

/**
 * Created by tsninging on 2016/10/26.
 */

public class LauncherPageApdater extends PagerAdapter {
    private int[] mImageId = new int[]{};
    private Context mContext;

    public LauncherPageApdater(Context context, int[] imageId) {
        mContext = context;
        if (imageId != null)
            this.mImageId = imageId;
    }


    @Override
    public int getCount() {
        return mImageId.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View inflate = null;
        if (position == 0) {
            inflate = LayoutInflater.from(mContext).inflate(R.layout.item_launcher_page_one, null);
            TextView tv = inflate.findViewById(R.id.tv_desc);
            tv.setText(mContext.getString(R.string.launcher_page_desc) + " V" + AppUtils.getAppVersionName());
        } else {
            inflate = LayoutInflater.from(mContext).inflate(R.layout.item_launcher_two, null);
            ImageView viewById = inflate.findViewById(R.id.iv_laucher);
            GlideUtils.GlideLoadPic(mContext, mImageId[position], viewById);
        }
        container.addView(inflate);
        return inflate;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
